Conditions | 1 |
Paths | 1 |
Total Lines | 71 |
Code Lines | 42 |
Lines | 71 |
Ratio | 100 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** global: maxUpload */ |
||
25 | View Code Duplication | function fileDrop(form) |
|
|
|||
26 | { |
||
27 | // Initialize Drag and Drop |
||
28 | var drop = $('#dropzone-box').dropzone( |
||
29 | { |
||
30 | url: form.attr('action'), |
||
31 | autoProcessQueue: false, |
||
32 | parallelUploads: 1, |
||
33 | maxFiles: 1, |
||
34 | maxFilesize: maxUpload, |
||
35 | addRemoveLinks: true, |
||
36 | chunking: true, |
||
37 | chunkSize: 1000000, |
||
38 | parallelChunkUploads: false, |
||
39 | method: "POST", |
||
40 | init: function() |
||
41 | { |
||
42 | var myDrop = this; |
||
43 | form.on('submit', function(e, formData) |
||
44 | { |
||
45 | e.preventDefault(); |
||
46 | if(myDrop.getQueuedFiles().length > 0) |
||
47 | { |
||
48 | myDrop.processQueue(); |
||
49 | $('#forProgressBar').show(); |
||
50 | $('.submit-button').attr('disabled', true); |
||
51 | } |
||
52 | else |
||
53 | { |
||
54 | $.post(form.attr('action'), form.serialize(), function(data) |
||
55 | { |
||
56 | uploadComplete(data); |
||
57 | }); |
||
58 | } |
||
59 | }); |
||
60 | this.on('sending', function(file, xhr, formData) |
||
61 | { |
||
62 | var formArray = form.serializeArray(); |
||
63 | $.each(formArray, function() |
||
64 | { |
||
65 | formData.append(this.name, this.value); |
||
66 | }); |
||
67 | }); |
||
68 | this.on('uploadprogress', function(progress) |
||
69 | { |
||
70 | var prog = Math.round(progress.upload.progress); |
||
71 | |||
72 | if(prog != 100) |
||
73 | { |
||
74 | $("#progressBar").css("width", prog+"%"); |
||
75 | $("#progressStatus").text(prog+"%"); |
||
76 | } |
||
77 | // $("#progressBar").css("width", Math.round(progress.upload.progress)+"%"); |
||
78 | // $("#progressStatus").text(Math.round(progress.upload.progress)+"%"); |
||
79 | }); |
||
80 | this.on('reset', function() |
||
81 | { |
||
82 | $('#form-errors').addClass('d-none'); |
||
83 | }); |
||
84 | this.on('success', function(files, response) |
||
85 | { |
||
86 | console.log(response); |
||
87 | uploadComplete(response); |
||
88 | }); |
||
89 | this.on('errormultiple', function(file, response) |
||
90 | { |
||
91 | uploadFailed(response); |
||
92 | }); |
||
93 | } |
||
94 | }); |
||
95 | } |
||
96 | |||
194 |